<#include "../common/macro.ftl">
<@page>
<body xmlns="http://www.w3.org/1999/html">

<div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
        <a lay-href="">主页</a>
        <a><cite>组件</cite></a>
        <a><cite>数据表格</cite></a>
        <a><cite>开启复选框</cite></a>
    </div>
</div>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">课题组数据源</div>
                <div class="layui-card-body">


                    <div class="test-table-reload-btn" style="margin-bottom: 10px;" >
                        <form id="queryForm" action="/topicCount/exportExcel" >
                       <table id="xxxxx" align="left" cellspacing="10" style="border-collapse:separate; border-spacing:20px 20px;">
                            <tr>
                                <th>
                                    是否有效
                                </th>
                                <th>
                                        <select id="input_isEffect" name="isEffect">
                                            <option value="">全部</option>
                                            <option value="1">有效</option>
                                            <option value="0">无效</option>
                                        </select>
                                </th>
                                <th>
                                    维修方：
                                </th>
                                <th>
                                    <select id="input_maintenanceProviderOrganizationId" name="maintenanceProviderOrganizationId">
                                        <option value="">全部</option>
                                            <#list maintenanceProviderMap?keys as key>
                                                <option value="${key}">${maintenanceProviderMap[key]}</option>
                                            </#list>
                                    </select>
                                </th>

                                <th>
                                    医院：
                                </th>
                                <th>
                                    <select id="input_hospitalOrganizationId" name="hospitalOrganizationId">
                                        <option value="">全部</option>
                                                <#list hospitalMap?keys as key>
                                                    <option value="${key}">${hospitalMap[key]}</option>
                                                </#list>
                                    </select>
                                </th>

                                <th>
                                    工单状态：
                                </th>
                                <th>
                                    <select id="input_status" name="status">
                                        <option value="">全部</option>
                                        <option value="completed">完成</option>
                                        <option value="to_be_confirmed">等待确认</option>
                                        <option value="closed">关闭</option>
                                        <option value="under_repair">维修中</option>
                                        <option value="newly">等待接修</option>
                                    </select>
                                </th>
                            </tr>
                            <tr>
                                <th>
                                    工单编号：
                                </th>
                                <th>
                                    <div class="layui-inline">
                                        <input class="layui-input" id="input_mtCode" name="mtCode" autocomplete="off">
                                    </div>
                                </th>
                            </tr>
                       </table>
                        </form>
                    </div>

                        <div class="layui-btn-group" style="margin-bottom: 10px;">
                        <button class="layui-btn layui-btn-primary" id="searchbt" data-type="reload">搜索</button>
                        </div>
                        <hr/>
                        <div class="layui-btn-group" style="margin-bottom: 10px;">
                        <button class="layui-btn layui-btn-sm layui-btn-primary" id="doEffectFalse">
                            <i class="layui-icon"></i>标记无效
                        </button>
                        <button class="layui-btn layui-btn-sm layui-btn-primary" id="doEffectTrue">
                            <i class="layui-icon"></i>标记有效
                        </button>
                        <button class="layui-btn layui-btn-sm layui-btn-primary" id="exportsExcel">
                            <i class="layui-icon"></i>导出
                        </button>
                    </div>
                        <div id="exxxx">
                    <table class="layui-hide" id="test-table-checkbox"></table>
                        </div>
                </div>
            </div>
        </div>
    </div>
</div>
</@page>

<script type="text/html" id="iscommentTpl">
    {{#  if(d.iscomment == 0){ }}
    未评价
    {{#  }else if(d.iscomment== 1){ }}
    有评价
    {{# } }}
</script>
<script type="text/html" id="isEffectTpl">
    {{#  if(d.isEffect == 0){ }}
    无效
    {{#  }else if(d.isEffect== 1){ }}
    有效
    {{# } }}
</script>
<script type="text/html" id="statusTpl">
    {{#  if(d.status == 'completed'){ }}
    完成
    {{#  }else if(d.status == 'to_be_confirmed'){ }}
    等待确认
    {{#  }else if(d.status == 'closed'){ }}
    关闭
    {{#  }else if(d.status == 'under_repair'){ }}
    维修中
    {{# }else { }}
    等待接修
    {{# } }}
</script>

<script src="${static}/layui/tableExport.js"></script>
<script src="${static}/layui/base64.js"></script>



<script>
    layui.config({
        base: '${static}/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table'], function(){
        var table = layui.table;



        table.render({
            elem: '#test-table-checkbox'、、
            ,id: 'idTest'
            ,url: 'topicCount/maintenanceTicketsData'
            ,totalRow: true //开启合计行
            ,cols: [[
                {type:'checkbox',fixed: 'left'}
                ,{field:'maintenanceTicketsId', title: '工单ID', sort: true, width: 100, fixed: 'left'}
                ,{field:'isEffect', title: '是否有效', width: 60, templet: '#isEffectTpl', totalRow: true}
                ,{field:'hospitalName', title: '所属医院', width: 200, totalRow: true}
                ,{field:'maintenanceProviderName', title: '维修方', width: 280, totalRow: true}
                ,{field:'maintenanceTicketsCode', title: '工单编号', width: 100, totalRow: true}
                ,{field:'status', title: '工单状态', width: 100, templet: '#statusTpl', totalRow: true}
                ,{field:'itemName', title: '设备名称', width: 200, totalRow: true}
                ,{field:'itemBrand', title: '品牌', width: 200, totalRow: true}
                ,{field:'itemModel', title: '型号', width: 200, totalRow: true}
                ,{field:'createdAtStr', title: '报修时间', width: 200, totalRow: true}
                ,{field:'outsourcingTookAtStr', title: '接修时间', width: 200, totalRow: true}
                ,{field:'finishedAtStr', title: '完成维修时间', width: 200, totalRow: true}
                ,{field:'respTime', title: '响应时长（小时）', width: 200, totalRow: true}
                ,{field:'arrivalTime', title: '工程师到场时长（小时）', width: 200, totalRow: true}
                ,{field:'arrivedTime', title: '配件到场时长（小时）', width: 200, totalRow: true}
                ,{field:'finishedTime', title: '完成维修时长（小时）', width: 200, totalRow: true}
                ,{field:'errorTime', title: '故障间隔时长（小时）', width: 200, totalRow: true}
                ,{field:'iscomment', title: '是否有评价', width: 200, templet: '#iscommentTpl', totalRow: true}
                ,{field:'satisfactionScore', title: '整体满意度得分', width: 200, totalRow: true}
                ,{field:'respScore', title: '响应速度得分', width: 200, totalRow: true}
                ,{field:'arrivalScore', title: '到场时间得分', width: 200, totalRow: true}
                ,{field:'fixScore', title: '维修效率得分', width: 200, totalRow: true}
                ,{field:'moneyScore', title: '维修价格得分', width: 200, totalRow: true}
                ,{field:'createdAtStr', title: '报修时间', width: 200, totalRow: true}
                ,{field:'signContent', title: '备注', width: 200, fixed: 'right'}
            ]]
            ,page: true
            ,done: function(res, curr, count){
                //如果是异步请求数据方式，res即为你接口返回的信息。
                //如果是直接赋值的方式，res即为：{data: [], count: 99} data为当前页数据、count为数据总长度
                console.log(res);

                //得到当前页码
                console.log(curr);

                //得到数据总量
                console.log(count);
            }
        });


        var $ = layui.$, active = {
            reload: function(){
                debugger;
                var input = {};
                input.isEffect = $("#input_isEffect").val();
                input.mtCode = $("#input_mtCode").val();
                input.status = $("#input_status").val();
                input.maintenanceProviderOrganizationId = $("#input_maintenanceProviderOrganizationId").val();
                input.hospitalOrganizationId = $("#input_hospitalOrganizationId").val();


                var demoReload = $('#test-table-demoReload');

                //执行重载
                table.reload('idTest', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                        isEffect: input.isEffect,
                        mtCode: input.mtCode,
                        status: input.status,
                        maintenanceProviderOrganizationId: input.maintenanceProviderOrganizationId,
                        hospitalOrganizationId: input.hospitalOrganizationId,
                    }
                });
            }
        };

        $('#searchbt').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        $("#doEffectFalse").click(function () {
            doEffect('0');

        });

        $("#doEffectTrue").click(function () {
            doEffect('1');

        });

        $("#exportsExcel").click(function(){
            debugger;
            $("#queryForm").submit();
            /*var form = $('<form></form>');
            form.attr('method', 'post');

            form.attr('action', '/topicCount/exportExcel');

            var isEffect_input = $('<input  name="isEffect" type="hidden" />');
            isEffect_input.attr('value',  $("#input_isEffect").val());

            var mtCode_input = $('<input  name="mtCode" type="hidden" />');
            mtCode_input.attr('value',  $("#input_mtCode").val());

            var status_input = $('<input  name="status" type="hidden" />');
            status_input.val($("#input_status").val());

            var maintenanceProviderOrganizationId_input = $('<input  name="maintenanceProviderOrganizationId" type="hidden" />');
            maintenanceProviderOrganizationId_input.attr('value',  $("#input_maintenanceProviderOrganizationId").val());

            var hospitalOrganizationId_input = $('<input  name="hospitalOrganizationId" type="hidden" />');
            hospitalOrganizationId_input.attr('value',  $("#input_hospitalOrganizationId").val());


            form.append(isEffect_input);
            form.append(mtCode_input);
            form.append(status_input);
            form.append(maintenanceProviderOrganizationId_input);
            form.append(hospitalOrganizationId_input);
            form.submit();

            $("#queryForm").submit();*/
            /*debugger;

            medatc('topicCount/exportExcel', input, function (result) {

            });*/



        });




        function doEffect(type) {
            debugger;
            var checkStatus = table.checkStatus('idTest');
            var data = checkStatus.data;
            if (data.length <= 0) {
                return false;
            }

            var array = new Array();
            for (var i=0; i<data.length; i++) {
                array[i] = data[i].maintenanceTicketsId;
            }

            var msg = '';
            var input = {};
            input.maintenanceTicketsIds = array;
            input.type = type;
            if (type == '0') {
                msg = '确定要令选中的' + data.length + '条失效吗？'
                layer.prompt({title: '备注'}, function(value, index){
                    input.signContent = value;
                    signConfirm(msg, input);
                    layer.close(index);
                });
            } else {
                msg = '确定要令选中的' + data.length + '条生效吗？'
                input.signContent='';
                signConfirm(msg, input);
            }
        }

    });

    function signConfirm(msg, input) {
        layer.confirm(msg, {
            btn: ['确定','取消'] //按钮
        }, function(){
            medatc('topicCount/doEffect', input, function (result) {
                layer.msg('操作成功！', {icon: 1},function () {
                    window.parent.refreshTab();
                });

            });

        }, function(){

        });
    }
</script>
</body>
</html>
